﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="menetlusinfo_maarus", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(MenetlusinfoMaarus))]
    public class MenetlusinfoMaarusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMenetlusinfoMaarus clazz;
        
        public MenetlusinfoMaarusSerializer(IMenetlusinfoMaarus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("otsuse_nr");
            if (clazz.OtsuseNr!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OtsuseNr))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : OtsuseNr");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("otsuse_liik");
            if (clazz.OtsuseLiik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OtsuseLiik))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : OtsuseLiik");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("otsuse_kpv");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.OtsuseKpv))).ToString());
            Writer.WriteEndElement();
            if (clazz.JoustKpv!=null) {
                Writer.WriteStartElement("joust_kpv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.JoustKpv))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Joust!=null) {
                Writer.WriteStartElement("joust");
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", "x_joustumise_tunnus");
                Writer.WriteString(clazz.Joust.ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("kandeliik");
            if (clazz.Kandeliik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.Kandeliik))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            if (clazz.Lisatahtaeg!=null) {
                Writer.WriteStartElement("lisatahtaeg");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Lisatahtaeg))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.MaaruseTekst!=null) {
                Writer.WriteStartElement("maaruse_tekst");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.MaaruseTekst))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="otsuse_nr") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>menetlusinfo_maarus>otsuse_nr");
                }
                clazz.OtsuseNr = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("otsuse_nr")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>menetlusinfo_maarus>otsuse_nr", Reader.LocalName);
            }
            if (Reader.LocalName=="otsuse_liik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>menetlusinfo_maarus>otsuse_liik");
                }
                clazz.OtsuseLiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("otsuse_liik")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>menetlusinfo_maarus>otsuse_liik", Reader.LocalName);
            }
            if (Reader.LocalName=="otsuse_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>menetlusinfo_maarus>otsuse_kpv");
                }
                clazz.OtsuseKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("otsuse_kpv")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>menetlusinfo_maarus>otsuse_kpv", Reader.LocalName);
            }
            if (Reader.LocalName=="joust_kpv") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.JoustKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("joust_kpv")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="joust") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Joust = new global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.XJoustumiseTunnus(Reader.ReadElementString("joust"));
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="kandeliik") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Kandeliik = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("kandeliik")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>menetlusinfo_maarus>kandeliik", Reader.LocalName);
            }
            if (Reader.LocalName=="lisatahtaeg") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Lisatahtaeg = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("lisatahtaeg")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="maaruse_tekst") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.MaaruseTekst = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("maaruse_tekst")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
